				package com.qaplus.controller;

import java.io.OutputStream;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import com.qaplus.constant.ErrorCode;
import com.qaplus.entity.QaUser;
import com.qaplus.excel.adapter.ExcelAdapter;
import com.qaplus.exception.ParameterException;
import com.qaplus.service.BoardService;
import com.qaplus.utils.SuperDate;
import com.qaplus.utils.excel.ColumnName;
import com.qaplus.utils.excel.ExcelUtil;
import com.qaplus.utils.excel.sheet.ExcelSheet;

/**
 * 页面跳转和测试的类
 * 
 * @author wb-zc189961
 *
 */
@Controller
@RequestMapping("index")
public class IndexController  extends SuperController{
	@Resource
	private BoardService boardService;
	
	@RequestMapping("to_login")
	public String toLogin() {
		return "common/login";
	}

	@RequestMapping("to_stu_add_q")
	public String toStuAddQ() {
		return "student/s_add_q";
	}

	@RequestMapping("to_stu_list_q")
	public String toStuListQ() {
		return "student/s_list_q";
	}

	@RequestMapping("to_recommend_file")
	public String toStuListA() {
		return "common/recommend_file";
	}

	@RequestMapping("to_home")
	public String toHome() {
		return "common/home";
	}

	@RequestMapping("to_teacher_a")
	public String toTeacherA() {
		return "teacher/t_a";
	}

	@RequestMapping("to_stu_q_chart")
	public String toQuestionChart() {
		return "common/q_chart";
	}

	@RequestMapping("to_t_list_q")
	public String toTeacherListA() {
		return "teacher/t_list_q";
	}

	@RequestMapping("to_add_recommend")
	public String toAddRecommend() {
		return "common/add_recommend";
	}

	@RequestMapping("to_class_list")
	public String toClassList() {
		return "teacher/class_list";
	}

	// 用户维护页面
	@RequestMapping("to_user_list")
	public String toUserList() {
		return "teacher/user_list";
	}

	@RequestMapping("to_tea_q_list")
	public String toTeaQuestionList() {
		return "teacher/tea_q_list";
	}

	@RequestMapping("to_add_homework")
	public String toTeaAddHomework() {
		return "teacher/tea_add_homework";
	}

	@RequestMapping("to_homework_list")
	public String toHomeworkList() {
		return "student/homework_list";
	}

	@RequestMapping("to_homework_manage")
	public String toHomeworkManage() {
		return "teacher/homework_manage";
	}

	@RequestMapping("to_answer_homework")
	public String toAnswerHomework() {
		return "student/answer_homework";
	}

	@RequestMapping("to_undo_task")
	public String toUndoTask() {
		return "common/undo_task";
	}

	@RequestMapping("to_update_my_info")
	public String toUpdateMyInfo() {
		return "common/update_my_info";
	}

	@RequestMapping("to_board")
	public String toBoard() {
		return "common/board";
	}

	@RequestMapping("to_hw_answer")
	public String toHomeworkAnswer() {
		return "common/homework_answer";
	}

	@RequestMapping("to_haha")
	public String toHaha() {
		return "home/home";
	}

	// ///下面是测试用的
	@RequestMapping("to_test")
	@ResponseBody
	public QaUser toTest(HttpServletRequest request) {
		QaUser user = new QaUser();
		user.setAge(1);
		user.setClassId("sdfds");	
		user.setEmail("sdfdsfds@qq.com");
		
		request.setAttribute("haha", "yi ding yao xian shi chu lai ya ");
		return user;
	}
	
	@RequestMapping("transation")
	public String testTracsation(){
		boardService.addBoard("content", "Y", "Y", "2016-05-14 00:00:00", "2017-05-14 00:00:00", "1,,3");
		throw new RuntimeException("添加公告出错了，不要插入进去");
	}
	
	@RequestMapping("to_test2")
	public ModelAndView test2() {
		QaUser user = new QaUser();
		user.setAge(1);
		user.setClassId("modleAndView");
		user.setEmail("modleAndView@qq.com");
		Map<String, QaUser> map = new HashMap<String, QaUser>();
		map.put("user", user);
		ModelAndView modelAndView = new ModelAndView("error/error", map);
		return modelAndView;
	}

	@RequestMapping("to_ll")
	public String toLL() {
		return "common/ll";
	}

	@RequestMapping("test_export_excel")
	public void testExportExcel(HttpServletResponse response) throws Exception {
	}

	// ok
	@RequestMapping("test_exception")
	public String testException() throws Exception {
		throw new ParameterException(ErrorCode.FAUILURE,
				ErrorCode.FAUILURE.getDesc());
	}

	// ok
	@RequestMapping("test_request_body")
	public void testRequestBody(@RequestBody QaUser user) {
		// System.out.println(user);
	}
}
